//
//  Todo.m
//  DoIT
//
//  Created by gex on 14/11/10.
//  Copyright (c) 2014年 gex. All rights reserved.
//

#import "Todo.h"
#import "NSDate+Utils.h"

@implementation Todo

-(Todo *)initWithContent:(NSString *)content{
    if (self=[super init]) {
        self.content = content;
        self.status = [NSNumber numberWithInt:TodoStatusDoing];
        self.creationTime = [NSDate dateLocal];
        self.modifyTime = [NSDate dateLocal];
    }
    return self;
}
-(Todo *)initWithDictionary:(NSDictionary *)dic{
    NSNumber *creationTime = [dic objectForKey:@"creationTime"];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[creationTime doubleValue]];
    [dic setValue:date forKey:@"creationTime"];
    
    NSNumber *modifyTime = [dic objectForKey:@"modifyTime"];
    date = [NSDate dateWithTimeIntervalSince1970:[modifyTime doubleValue]];
    [dic setValue:date forKey:@"modifyTime"];
    
    if (self=[super init]) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
#pragma mark - 静态方法
+(Todo *)todoWithContent:(NSString *)content{
    return [[Todo alloc] initWithContent:content];
}

- (NSString *)description{
    return [NSString stringWithFormat:@"id=%@,content=%@,status=%@,creationTime=%@,modifyTime=%@",self.Id,self.content,self.status,[self.creationTime description],[self.modifyTime description]];
}

@end
